package com.szeldon.pj.jps.qres;

import java.util.ArrayList;
import java.util.List;

/**
 * Class created for CW02 of JPS. Created because there was a need to create something simple to contain information
 * about nodes of tree that contains queries. AST tree will be created in the future.
 * 
 * @author szeldon
 * 
 */
public class TempNode {

    private TempNode parent;

    private List<TempNode> kids = new ArrayList<TempNode>();

    private String operator;

    private AbstractQueryResult result;

    /**
     * Creates node. Parent may be null, if this node is a root. Operator and result can't both have values or be null.
     * 
     * @param parent
     * @param operator
     * @param result
     */
    public TempNode(TempNode parent, String operator, AbstractQueryResult result) {
        this.parent = parent;
        if (operator != null && result != null) {
            throw new IllegalArgumentException("Operator and result can't both have values.");
        }
        if (operator == null && result == null) {
            throw new IllegalArgumentException("Operator and result can't both be null.");
        }
        this.operator = operator;
        this.result = result;
    }

    public boolean isLeaf() {
        if (kids.size() == 0) {
            return true;
        } else {
            return false;
        }
    }

    public boolean isOperator() {
        if (operator == null) {
            return false;
        } else {
            return true;
        }
    }

    /**
     * 
     * @param kid
     */
    public void addKid(TempNode kid) {
        kids.add(kid);
    }

    public List<TempNode> getKids() {
        return kids;
    }

    public AbstractQueryResult getResult() {
        return result;
    }

    public String getOperator() {
        return operator;
    }

}
